package com.oh.iris.entity;

import com.alibaba.fastjson2.JSON;

public class MessagePacket {

    /**
     * 类型 1文本消息, 2图片消息, 3语音消息, 4视频消息, 5表示心跳包, 6表示超时包
     */
    private byte type;

    /**
     *
     * 系统编号 1表示ios端, 2表示安卓端, 3表示PC端 9其他
     */
    private byte origin;

    /**
     * 时间戳
     */
    private long timeStamp;


    /**
     * 内容长度
     */
    private int length;

    /**
     * 内容
     */
    private byte[] content;

    /**
     * 目标ID
     */
    private String targetId;

    public MessagePacket() {
    }

    /**
     *
     * @param type 信息标志 1文本消息, 2图片消息, 3语音消息, 4视频消息, 5表示心跳包, 6表示超时包
     * @param origin 类型  系统编号 1表示ios端, 2表示安卓端, 3表示PC端 9其他
     * @param timeStamp 时间戳
     * @param content 内容
     */
    public MessagePacket(byte type, byte origin, long timeStamp, byte[] content) {
        this.type = type;
        this.origin = origin;
        this.timeStamp = timeStamp;
        this.content = content;
        this.length = content.length;
    }

    public MessagePacket(byte type, byte origin, String targetId, byte[] content) {
        this.type = type;
        this.origin = origin;
        this.timeStamp = System.currentTimeMillis();
        this.content = content;
        this.length = content.length;
        this.targetId = targetId;
    }

    public byte getType() {
        return type;
    }

    /**
     * 类型  系统编号 1表示ios端, 2表示安卓端, 3表示PC端
     * @param type
     */
    public void setType(byte type) {
        this.type = type;
    }

    public byte getOrigin() {
        return origin;
    }

    public void setOrigin(byte origin) {
        this.origin = origin;
    }

    public long getTimeStamp(){
        return timeStamp;
    }

    public void setLength(int length){
        this.length = length;
    }

    public int getLength(){
        return this.length;
    }

    public void setTimeStamp(long timeStamp){
        this.timeStamp = timeStamp;
    }

    public byte[] getContent() {
        return content;
    }

    public String getTargetId(){
        return this.targetId;
    }

    public void setTargetId(String targetId){
        this.targetId = targetId;
    }

    /**
     * 内容
     * @param content
     */
    public void setContent(byte[] content) {
        this.content = content;
        this.length = content.length;
    }

    /**
     * 转成json
     * @return json str
     */
    public String toJson(){
        return JSON.toJSONString(this);
    }
}
